home *** CD-ROM | disk | FTP | other *** search
- Frequently Asked Questions (FAQS);faqs.378
-
-
-
- For Motif 1.1.1, 1.1.2 and 1.1.3 you will need to compile Xlib and Xt with a
- MOTIF_BC flag set to YES (page 8, section 3.3 of the R5 release notes), or
- you'll also have a link problem (LowerCase) and a fatal run time problem
- (XContext manager). If your applications come up with "Unknown keysym name:
- osfActivate" errors, check the variable ProjectRoot. The name
- /$PROJECTROOT/lib/XKeysymDB will have been wired into your Xlib.
-
- In Motif 1.1.0, XtCallCallback uses NULL as the first argument instead of a
- widget ID. This was ok under R4, but must be changed in the source for R5. It
- was changed by OSF from Motif 1.1.1 onward.
-
- Mrm won't work at all (can't link since it uses an X private variable that has
- disappeared in R5). Thre is an MIT patch that may fix this?? [I confess
- ignorance of Mrm and UIL].
-
- -----------------------------------------------------------------------------
- Subject: 18) How can I find which version of Motif I have?
-
- Answer: The macro XmVERSION gives you the version number. The macro
- XmREVISION gives you the major revision number. The macro XmVersion combines
- these e.g. a value of 1002 is Motif 1.2.
-
- To find the minor revision number is not easy. From Motif 1.1.3 onwards, try
- this:
-
- 'strings `which mwm` | grep OSF'.
-
- to get the full version number e.g. 1.1.3.
-
-
- -----------------------------------------------------------------------------
- Subject: 19) TOPIC: LITERATURE
-
- -----------------------------------------------------------------------------
- Subject: 20) What books should I read or do I need to program using Motif?
-
- [Last modified: November 92]
-
- Answer: Ken Lee of the DEC Western Software Laboratory (klee@wsl.dec.com)
- regularly posts to comp.windows.x and ba.windows.x a list of reference books
- and articles on X and X programming. In FAQ comp.windows.x an extract of his
- list appears. Specifically for Motif programming, though:
-
- OSF/Motif Programmers Guide, Prentice-Hall 13-640525-8 (Motif 1.0) ISBN 0-13-
- 640681-5 (Motif 1.1) (NB: This makes use of the demo programs that you get
- with a Motif source license. The programs are not included and may or may not
- be available on your system.)
-
- OSF/Motif Programmers Reference Manual, Prentice-Hall 13-640517-17 (Motif 1.0)
- ISBN 0-13-640616-5 (Motif 1.1) You will need this for the system calls.
-
- OSF/Motif Style Guide, Prentice-Hall 13-640491-X (Motif 1.0) ISBN 0-13-
- 640673-4 (Motif 1.1) You will need this to get some idea of how to write
- programs with the correct `look and feel'.
-
- You should read at least one of the the non-OSF books on Motif:
-
- Young, Doug. "The X Window System: Applications and Programming with Xt (Motif
- Version)," Prentice Hall, 1989 (ISBN 0-13-497074-8). The excellent tutorial "X
- Window Systems Programming and Applications with Xt," (ISBN 0-13-972167-3)
- updated for Motif. [The examples from the Motif version are available on
- export in ~ftp/contrib/young.motif.tar.Z]
-
- Marshall Brain at brain@adm.csc.ncsu.edu posted a set of simple and useful
- Motif tutorials.
-
- Berlage, Thomas Berlage, OSF/Motif: Concepts and Programming, Addison-Wesley,
- UK, 1991. ISBN 0-201-55792-4.
-
- Johnson, Eric F. and Kevin Reichard, Power Programming Motif, MIS: Press,
- Portland, OR, 1991. ISBN 1-55828-059-6. Book with disk, ISBN 1-55828-061-8.
-
- Heller, Dan, The Motif Programming Manual, Volume 6 of the O'Reilly series on
- X. This is the most complete volume on Motif programming available. ISBN 0-
- 937175-70-6.
-
- Barkakati, Nabajyoti, W Window System Programming, SAMS. ISBN 0-672-22750-9.
- This contains a section on Motif.
-
- Newmarch, Jan, The X Window System and Motif - A Fast Track Approach.
- Addison-Wesley, ISBN 0-201-53931-4.
-
- You will also need books and references on Xt such as:
-
- Asente, Paul J., and Swick, Ralph R., "X Window System Toolkit, The Complete
- Programmer's Guide and Specification", Digital Press, 1990. The bible on Xt.
- A treasury of information, excellent and invaluable. Distributed by Digital
- Press, ISBN 1-55558-051-3, order number EY-E757E-DP; and by Prentice- Hall,
- ISBN 0-13-972191-6.
-
- Nye, Adrian, and Tim O'Reilly, "X Toolkit Programming Manual, Volume 4,"
- O'Reilly and Associates, 1989. The folks at O'Reilly give their comprehensive
- treatment to programming with the MIT Intrinsics; R4 versions are now
- available, as is a Motif 1.1 version (Volume 4M).
-
-
- Flanagan, David, ed., "X Toolkit Reference Manual, Volume 5," O'Reilly and
- Associates, 1992a, Third Edition. A professional reference manual for the MIT
- X11R4 and X11R5 Xt.
-
- Books and reference manuals on Xlib may also be useful.
-
-
-
- -----------------------------------------------------------------------------
- Subject: 21) TOPIC: MWM
-
- -----------------------------------------------------------------------------
- Subject: 22) What is the difference between Motif and mwm?
-
- Answer: mwm is a window manager. Motif itself is made up of four parts: a
- User-Interface Guideline, an API toolkit of `C' routines which helps in the
- building of applications which conform to the Guideline, the window manager
- mwm, and a language UIL which is designed to ease user interface development.
- In general mwm will run an application built with any X-windows API, and in
- general an application built using the Motif toolkit will run under any window
- manager.
-
-
- -----------------------------------------------------------------------------
- Subject: 23) Does anyone have an alternative set of 3-D defaults for a
- monochrome screen?
-
- Answer: This is obviously a matter of taste. Some alternatives suggested
- include
-
- !Benjamin Schreiber, bs@osf.osf.org, bs@cs.brandeis.edu
- Mwm*foreground: black ! Actually, when a window is
- Mwm*background: white ! deactivated, the background
- Mwm*backgroundPixmap: 50_foreground ! becomes white, insted of
- Mwm*topShadowPixmap: white ! 50% foreground (grey)
-
- Mwm*activeForeground: black
- Mwm*activeBackground: white
- Mwm*activeBackgroundPixmap: 50_foreground
- Mwm*activeTopShadowPixmap: white
-
- Mwm*menu*backgroundPixmap: background
- Mwm*menu*topShadowPixmap: 50_foreground
-
- Mwm*title*foreground: black
- Mwm*title*background: white
- Mwm*title*backgroundPixmap: white
- Mwm*title*topShadowPixmap: 50_foreground
- Mwm*title*activeForeground: white
- Mwm*title*activeBackground: black
- Mwm*title*activeBackgroundPixmap: black
- Mwm*title*activeBottomShadowPixmap: 50_foreground
-
- Mwm*feedback*backgroundPixmap: white
-
- or
-
- ! From: tsang@isi.com (Kam C. Tsang)
- Mwm*background: White
- Mwm*activeBackground: White
- Mwm*activeBackgroundPixmap: 25_foreground
- Mwm*foreground: Black
- Mwm*activeForeground: Black
- Mwm*menu*background: white
- Mwm*menu*foreground: black
- xterm*Foreground: black
- xterm*Background: white
-
-
- or
-
- ! From: ucsd.edu!usc!snorkelwacker!paperboy!yee (Michael K. Yee)
- Mwm*cleanText: True
-
- Mwm*activeBackground: white
- Mwm*activeForeground: black
- Mwm*background: white
- Mwm*foreground: black
-
- Mwm*client*activeBackgroundPixmap: 50_foreground
- Mwm*client*activeTopShadowPixmap: foreground
- Mwm*client*activeBottomShadowPixmap: background
-
- !Mwm*client*background: white
- !Mwm*client*foreground: black
- Mwm*client*backgroundPixmap: 75_foreground
- Mwm*client*topShadowPixmap: foreground
- Mwm*client*bottomShadowPixmap: background
-
- !Mwm*feedback*background: white
- !Mwm*feedback*foreground: black
- Mwm*feedback*backgroundPixmap: 50_foreground
- !Mwm*feedback*topShadowPixmap: 25_foreground
- !Mwm*feedback*bottomShadowPixmap: background
-
- !Mwm*menu*background: white
- !Mwm*menu*foreground: black
- Mwm*menu*backgroundPixmap: foreground
- !Mwm*menu*topShadowPixmap: foreground
- !Mwm*menu*bottomShadowPixmap: background
-
- !Mwm*icon*background: white
- !Mwm*icon*foreground: black
- Mwm*icon*activeBackgroundPixmap: 50_foreground
- Mwm*icon*activeBottomShadowPixmap: foreground
- Mwm*icon*backgroundPixmap: 75_foreground
-
-
-
- -----------------------------------------------------------------------------
- Subject: 24) How can I modify the Motif window manager decorations?
-
- Answer: In resource files, use the window manager's client resource (which is
- the application) and the resource clientDecoration:
-
- Mwm*XClock.clientDecoration: none
-
- turns off all clock decorations. See the mwm(1) entry for other
- possibilities.
-
- Programmatically, set the VendorShell resource XmNmwmDecorations to
- appropriate values: MWM_DECOR_NONE (or a bitwise or of values).
-
- -----------------------------------------------------------------------------
- Subject: 25) How can I turn off the Motif window manager functions from the
- system menu?
- [Last modified: October 92]
-
- Answer: The user of an application can control functions in the system menu
- for an application using the mwm resource clientFunctions:
-
- mwm.application_name.clientFunctions: -resize -close
-
- Note that mwm will have to be restarted after putting this in their resource
- database.
-
-
- Answer: The writer of an application can only remove items. Be warned that
- your users will probably gnash their teeth, swear furiously at your product
- and stop using it if they discover that you have done this. (Especially if
- you have removed the Close button, your application has hung and it has taken
- up all of memory and swap so it can't be killed.) Much better is to catch the
- action gracefully as in the next question.
-
- #include <Xm/MwmUtil.h>
-
- XtVaGetValues(shell, XmNmwmFunctions, &int_val, NULL);
- int_val &= ~(MWM_FUNC_CLOSE | MWM_FUNC_ALL);
- XtVaSetValues(shell, XmNmwmFunctions, int_val, NULL);
-
-
-
- -----------------------------------------------------------------------------
- Subject: 26) How can tell I if the user has selected the "Close" item on the
- system menu attached to the top-level shell? I need to do some clean up
- before exiting.
-
- Answer: This works with R4 Intrinsics
-
- void FinalCleanupCB(w, client_data, call_data)
- Widget w;
- caddr_t client_data, call_data;
- {
- /* tidy up stuff here */
- ...
- /* exit if you want to */
- exit (0);
- }
-
- main()
- {
- Atom wm_delete_window;
-
- ...
- XtRealizeWidget(toplevel);
- ...
- wm_delete_window =
- XmInternAtom(XtDisplay(toplevel),
- "WM_DELETE_WINDOW", False);
- XmAddWMProtocolCallback(toplevel, wm_delete_window,
- FinalCleanupCB, NULL);
- XtMainLoop();
- }
-
- This will still kill the application. To turn this behaviour off so that the
- application is not killed, set the shell resource XmNdeleteResponse to
- XmDO_NOTHING. This means that users cannot kill your application via the
- system menu, and may be a bad thing.
-
- If you are running R3, Bob Hays (bobhays@spss.com) has suggested this:
- "Trapping on the delete window atom does not work as I cannot force my action
- routine to the top of the action list for the activity desired, so the window
- manager kills my window anyway BEFORE I can do anything about it. And, to
- make matters worse, the window manager (Motif in this case) tacks its atoms
- and handlers onto the window at some unknown point down the line after the
- creation of the shell widget as far as I can tell. So....
-
- I have a procedure as an action routine for ClientMessage. Then, if I get a
- property change event on the window manager protocols, I then tack on
- WM_SAVE_YOURSELF. If I get this request, I clean up (it seems to happen on
- WM_DELETE_WINDOW, BTW, if you remove WM_DELETE_WINDOW from the WM protocols
- atom) and exit. Works great and is less filling overall:-)."
-
-
- -----------------------------------------------------------------------------
- Subject: 27) Is there an mwm virtual desktop manager?
-
- Answer: Peter E. Wagner (pew@cs.brown.edu): Imagine that your "desktop"
- extends beyond the view provided by your monitor. A virtual window manager
- gives you access to the space beyond your viewport (i.e. your screen) by
- allowing you to move the viewport to other areas of the extended desktop.
-
- The first one is Solbourne's swm, which spawned vtwm/tvtwm/olvwm.
-
- David B. Lewis created one. suresh@unipalm.co.uk has further developed it
- into the UniPalm product DOORS, which is only available as a source code
- extension to the MOTIF window manager. The price of the source and unlimited
- right to distribute binaries is 10,000 pounds Sterling. Alternately, source
- and right to use within one company is 2,000 pounds Sterling. Contact Peter
- Dawe
-
- Unipalm Limited Voice: +44 (0) 223 420002
- 216 The Science Park Fax: +44 (0) 223 426868
- CAMBRIDGE
- CB4 4WA
-
-
-
- An enhancement request for such an object has been filed with OSF.
-
- -----------------------------------------------------------------------------
- END OF PART ONE
- --
- +----------------------+---+
- Jan Newmarch, Information Science and Engineering,
- University of Canberra, PO Box 1, Belconnen, Act 2616
- Australia. Tel: (Aust) 6-2012422. Fax: (Aust) 6-2015041
- Xref: bloom-picayune.mit.edu comp.windows.x.motif:13658 news.answers:4509
- Newsgroups: comp.windows.x.motif,news.answers
- Path: bloom-picayune.mit.edu!enterpoop.mit.edu!news.media.mit.edu!micro-heart-of-gold.mit.edu!wupost!uunet!munnari.oz.au!manuel.anu.edu.au!csc.canberra.edu.au!news
- From: jan@ise.canberra.edu.au (Jan Newmarch)
- Subject: Motif FAQ (Part 2 of 5)
- Message-ID: <1992Dec10.001605.10450@csc.canberra.edu.au>
- Followup-To: comp.windows.x.motif
- Keywords: FAQ question answer
- Sender: news@csc.canberra.edu.au
- Reply-To: jan@ise.canberra.edu.au (Jan Newmarch)
- Organization: University of Canberra
- Date: Thu, 10 Dec 92 00:16:05 GMT
- Approved: news-answers-request@MIT.Edu
- Expires: +1 months
- Lines: 764
-
- Archive-name: motif-faq/part2
- Last-modified: Thu December 12 1992
- Version: 2.12
-
-
-
- -----------------------------------------------------------------------------
- Subject: 28) TOPIC: MOTIF GENERATORS
-
- -----------------------------------------------------------------------------
- Subject: 29)* What prototyping tools are there to generate Motif code?
- [Last modified: November 92]
-
- Answer: [An FAQ is for "personal opinions" on these tools. I don't think it
- is appropriate to give such opinions through this particular posting, so I
- haven't included any.]
-
- `Prototyping tools' come in two forms: those that can be used to design the
- interface only (GUI builder), and those that go beyond this to give support
- for application code (User Interface Management Systems). There are a number
- of commercial and non-commercial tools of both kinds that will support the
- Motif interface. They include:
-
- GUI builders:
-
- Builder Xcessory
- X Build
- ExoCODE/xm
-
-
- UIMS:
-
- WINTERP
- ALEX
- Widget Creation Library
- UIMX
- Serpent
- TeleUse
- X-Designer
- XFaceMaker2
- MOTIFATION
- MetaCard
-
-
- Some contact addresses are:
-
- WINTERP: You may obtain the current source, documentation, and examples via
- anonymous ftp from host export.lcs.mit.edu: in directory contrib/winterp you
- will find the compress(1)'d tar(1) file winterp.tar.Z. If you do not have
- Internet access you may request the source code to be mailed to you by sending
- a message to winterp-source%hplnpm@hplabs.hp.com or hplabs!hplnpm!winterp-
- source.
-
- Serpent: The S/W is free (anonymous ftp) from ftp.sei.cmu.edu. For more info
- contact erik/robert at serpent-info@sei.cmu.edu.
-
- TeleUse: In the U.K., send mail to xtech@unipalm.co.uk or call +44 954 211862.
- In the US contact Telesoft at:
-
- TeleSoft, 5959 Cornerstone Court West, San Diego, CA 92121-9891
- Phone: +1 619-457-2700
- +1 619-452-1334 Fax
- Email: guisales@telesoft.com (Sales),
- guisupport@telesoft.com (Customer Support)
-
-
- Builder Xcessory from ICS. More details are available by sending a request to
- info@ics.com. Address: ICS Inc., 201 Broadway, Cambridge MA 02139, Tel. (617)
- 621-0060, Fax. (617) 621-9555
-
- X-Designer: From Imperial Software Technology in the UK. Email address is
- sales@ist.co.uk. (+44) 743 587055
-
- Recently, V.I. Corporation have become the distributor for the X-Designer
- product in the United States. In addition, IST and V.I. Corporation have
- developed a product called DVX-Designer that merges X-Designer with their GUI
- product called DataViews. Other merged products are in the works. For more
- information, people can contact:
-
- V.I. Corporation
- 47 Pleasant Street
- Northampton, MA 01060
- Phone: (413) 586-4144
- Fax: (413) 586-3805
- Email: vi@vicorp.com
-
-
- ExoCODE/xm: From Expert Object Corp., 7250 Cicero Avenue, Lincolnwood, IL
- 60646 (708)676-5555.
-
- X Build: From Nixdorf Computer (Waltham, MA) xbuild@nixdorf.com
-
-
- ExoCode: From EXOC (Chicago, IL)
-
- UIMX: Visual Edge Software Limited, 3870 Cote Vertu, St Laurent, Quebec, H4R
- 1V4, Phone: (514) 332-6430, Fax: (514) 332-5914, or: Visual Edge Software
- Ltd., 101 First Street, Suite 443, Los Altos, CA 94022, Phone: (415) 948-0753,
- Fax: (415) 948-0843
-
- The Widget Creation Library: The distribution is available in several ways.
- The preferred approach it for you to get the compressed tar file using
- anonymous ftp from:
-
- export.lcs.mit.edu (18.30.0.238) /contrib/Wcl.1.06.tar.Z
-
-
- XFaceMaker2: NSL - Non Standard Logics S.A., 57-59, rue Lhomond, 75005 Paris
- - France, Phone: +33 (1) 43.36.77.50, Fax: +33 (1) 43.36.59.78 email:
- requests@nsl.fr or requests%nsl.fr@inria.fr for information.
-
- Their North American office: Non Standard Logics, Inc., 4141 State Street,
- Suite B-11, Santa Barbara CA 93110, Tel: 805 964 9599, Fax: 805 964 4367
-
-
- MOTIFATION: AKA EDV, Universitaetsstrasse 125, 4630 Bochum, Germany, Tel: +49
- (0) 234 / 33397-0, Fax: +49 (0) 234 / 33397-40
-
-
- ALEX: For more information contact Michael Karliner on (+44) 81 566 2307 or
- E-mail to alex@s-strat.co.uk. ALEX Technologies, Waterman's Yard, 32a The
- Mall, Ealing, London W5, UK.
-
- MetaCard: MetaCard 1.0 is supported on five popular UNIX/X11 platforms: SPARC,
- Sun3, DECstation, HP-9000/300, and SCO ODT. An HP-9000/700 port is underway
- and should be available by the end of July. [They] plan to support IBM
- RS/6000, SGI Iris, and DG AViiON sometime fall '92. For more information, or
- to receive a free save-disabled but licensable copy of MetaCard, email to
- info@metacard.com or call 303- 447-3936. If you have anonymous FTP access to
- the Internet, you can download the current engines, documentation, and an
- unlicensed Home stack from ftp.metacard.com (128.138.213.21), directory
- MetaCard. Commercial users can get MetaCard from world.std.com
- (192.74.137.5), directory pub/Metacard. If you don't have an anonymous ftp
- access, you can also download MetaCard from The World using kermit or xmodem
- from the ~ftp/pub/MetaCard directory. Sign up by calling 617-739-0202 (voice)
- or via modem by dialing 617-739-9753 (7 bits even parity) and logging in as
- new.
-
- MetaCard 1.2 Beta 5 is now available for anonymous FTP from ftp.metacard.com
- (directory MetaCard/1.2B5), and ftp.uu.net (directory vendor/MetaCard/1.2B5).
-
-
- -----------------------------------------------------------------------------
- Subject: 30) TOPIC: TEXT WIDGET
-
- -----------------------------------------------------------------------------
- Subject: 31) Why does pressing <return> in a text widget do nothing? This
- happens using Motif 1.0 when I have a text widget inside a bulletin board (or
- form) inside a dialog shell. (In Motif 1.1 it is fixed for both text and list
- widgets.)
-
- Answer: In single line mode, pressing the <return> key usually invokes the
- activate() action, and in multi-line mode, the newline() action. However,
- whenever a widget is the child of a bulletin board widget which is the child
- of a dialog shell, the bulletin board forces all of its children to translate
- <return> to the bulletin board action Return() which is usually associated
- with the default button of the dialog. To restore the text actions of
- activate() or newline(), you need to overide the Return() action of the
- bulletin board.
-
-
- /* declarations */
- /* for a single line widget */
- char newTrans[] = "<Key>Return : activate()";
- /* for a multi line widget */
- char newTrans[] = "<Key>Return : newline()";
- XtTranslations transTable;
-
- /* in executable section */
-
- transTable = XtParseTranslationTable(newTrans);
-
- /* after creating but before managing text widget */
-
- XtOverrideTranslations(textWidget, transTable);
-
-
- -----------------------------------------------------------------------------
- Subject: 32) When I add text to a scrolling text widget how can I get the new
- text to show?
-
- Answer: Use the call undocumented in Motif 1.0
-
- void XmTextShowPosition(w, position)
- Widget w;
- XmTextPosition position;
-
- where the position is the number of characters from the beginning of the
- buffer of the text to be displayed. If you don't know how many characters are
- in the buffer, use another call undocumented in Motif 1.0
-
- position = XmTextGetLastPosition(w)
-
-
- -----------------------------------------------------------------------------
- Subject: 33)* Does the text widget support 16 bit character fonts?
-
-
- [Last modified: November 92]
-
- Answer: R5 has support for 16 bit character sets, and Motif 1.2 uses that.
- Neither Motif 1.0 nor 1.1 support 16 bit sets.
-
- -----------------------------------------------------------------------------
- Subject: 34) How can I stop the text widget from echoing characters typed? I
- need to turn off echo for password input.
-
- Answer: Use the modifyVerifyCallback to tell when input is received. Set the
- `doit' field in the XmTextVerifyCallbackStruct to False to stop the echo. In
- Motif 1.0 this will cause a beep per character: Live with it, because at 1.1
- you can turn it off. Note that password hiding is inherently insecure in X -
- someone may have an X grab on the keyboard and be reading all characters typed
- in anyway.
-
- Another solution often proposed is to set the foreground and background
- colours to be the same, effectively hiding the text. This has a major flaw:
- someone may select the text (triple click the mouse to get the line), and then
- paste the password into say an xterm with *different* foreground and
- background colours. This immediately shows the password.
-
- -----------------------------------------------------------------------------
- Subject: 35) How can I replace characters typed with say a `*'? I want to
- replace input for password entry.
-
- Answer: In Motif 1.1 Use the modifyVerifyCallback to tell when input is
- received. Set text->ptr in the callback structure to '*'. This does not work
- under 1.0 because of an oversight in which changes to this are ignored. In
- Motif 1.0, what you can do is set the doit flag to 'false' so the text is not
- displayed. Then set a static boolean to True to prevent re-entrance. Next
- call XmTextReplace() to display your '*'. then reset your re-entrance flag to
- False. XmTextReplace() will call the XmNmodifyVerify callback. To prevent
- getting into an infinite loop, you need the re-entrance flag.
-
- The following program from Dan Heller illustrates this:
- --------------
- /* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
- * This program is freely distributable without licensing fees and
- * is provided without guarantee or warranty expressed or implied.
- * This program is -not- in the public domain. This program appears
- * in the Motif Programming Manual, O'Reilly Volume 6.
- */
-
- /* passwd.c -- prompt for a passwd. Meaning, all input looks like
- * a series of *'s. Store the actual data typed by the user in
- * an internal variable. Don't allow paste operations. Handle
- * backspacing by deleting all text from insertion point to the
- * end of text.
- */
- #include <Xm/Text.h>
- #include <Xm/LabelG.h>
- #include <Xm/RowColumn.h>
- #include <ctype.h>
-
- void check_passwd();
- char *passwd; /* store user-typed passwd here. */
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- Widget toplevel, text_w, rowcol;
- XtAppContext app;
-
- toplevel = XtVaAppInitialize(&app, "Demos",
- NULL, 0, &argc, argv, NULL, NULL);
-
- rowcol = XtVaCreateWidget("rowcol",
- xmRowColumnWidgetClass, toplevel,
- XmNorientation, XmHORIZONTAL,
- NULL);
-
- XtVaCreateManagedWidget("Password:",
- xmLabelGadgetClass, rowcol, NULL);
- text_w = XtVaCreateManagedWidget("text_w",
- xmTextWidgetClass, rowcol, NULL);
-
- XtAddCallback(text_w, XmNmodifyVerifyCallback, check_passwd, NULL);
- XtAddCallback(text_w, XmNactivateCallback, check_passwd, NULL);
-
- XtManageChild(rowcol);
- XtRealizeWidget(toplevel);
- XtAppMainLoop(app);
- }
-
- void
- check_passwd(text_w, unused, cbs)
- Widget text_w;
- XtPointer unused;
- XmTextVerifyCallbackStruct *cbs;
- {
- char *new;
- int len;
-
- if (cbs->reason == XmCR_ACTIVATE) {
- printf("Password: %s\n", passwd);
- return;
- }
-
- if (cbs->text->ptr == NULL) { /* backspace */
- cbs->endPos = strlen(passwd); /* delete from here to end */
- passwd[cbs->startPos] = 0; /* backspace--terminate */
- return;
- }
-
- if (cbs->text->length > 1) {
- cbs->doit = False; /* don't allow "paste" operations */
- return; /* make the user *type* the password! */
- }
-
- new = XtMalloc(cbs->endPos + 2); /* new char + NULL terminator */
- if (passwd) {
- strcpy(new, passwd);
- XtFree(passwd);
- } else
- new[0] = NULL;
- passwd = new;
- strncat(passwd, cbs->text->ptr, cbs->text->length);
- passwd[cbs->endPos + cbs->text->length] = 0;
-
- for (len = 0; len < cbs->text->length; len++)
- cbs->text->ptr[len] = '*';
- }
-
-
- -----------------------------------------------------------------------------
- Subject: 36) How can I best add a large piece of text to a scrolled text
- widget? In some versions of Motif 1.0 even using XmTextSetString, it insists
- on adding the text one line at a time, adjusting the scroll bar each time. It
- looks awful and is slow.
-
- Answer: If you don't have this problem, use XmTextSetString to set all of the
- text in the widget. If you do have this slowdown problem even using
- XmTextSetString, unmanage the widget, add the text and then manage it again.
- This may cause the window to blink, but you have to put up with that or switch
- to a different version of Motif.
-
- -----------------------------------------------------------------------------
- Subject: 37) How can I highlight text in the Text widget?
-
- Answer: From: argv@zipcode.com (Dan Heller)
-
- If you don't need font or color changes, you can do all this using a Text
- widget very easily [in Motif 1.1, anyway].
-
- loop() {
- pos = offset_of_pattern_in_text_widget(pattern, text_w);
- search_len = strlen(pattern);
- XmTextSetHighlight(text_w, pos, pos+search_len,
- XmHIGHLIGHT_SELECTED);
- }
-
-
- There are two choices for highlighting: reverse video (HIGHLIGHT_SELECTED) and
- underlined (HIGHLIGHT_SECONDARY_SELECTED). Be careful that your users won't
- confuse your highlights with actual selections!
-
- -----------------------------------------------------------------------------
- Subject: 38) How can I select all of the text in a widget programmatically?
- So that some initial text is displayed, but anything typed replaces it.
-
- Answer: XmTextSetSelection(Text1, 0, XmTextGetLastPosition(Text1), event-
- >xbutton.time);
-
- where Text1 is the widget in question (obviously) and event is some event that
- triggered this call. You can use XtLastTimestampProcessed( display) instead
- of xbutton.time if you don't happen to have an event pointer handy.
-
-
-
-
- -----------------------------------------------------------------------------
- Subject: 39) How can I change colours of text in the Text widget? I want some
- of the text in one colour, some in another.
-